class Person:
    def __init__(self):
        self.age=0
    def __setattr__(self, key, value):
        if (key=='nianling'):
            if (value<10):
                self.age=value
            else:
                print('年龄不符和条件')
        else:
            self.__dict__[key]=value#存储age的值，不写这句age的值总是None

    def __getattr__(self, item):
        if item=='nianling':
            return
p=Person()
p.nianling=20
print(p.nianling)
print(p.g)